use bevy::{ecs::event::Event, math::IVec2};

use crate::config::goods_config::SeedItem;

use super::component::FurnitureComponent;

///鼠标左键点击事件
#[derive(Event)]
pub struct EMouseLeftClick {
    pub pos: IVec2,
}

///下一天事件
#[derive(Event)]
pub struct ENextDay;

///删除作物事件
#[derive(Event)]
pub struct EDelCrop {
    pub pos: IVec2,
}

///种植作物事件
#[derive(Event)]
pub struct EPlantCrop {
    pub pos: IVec2,
    pub day: u32,
    pub curr_stages: u32,
    pub seed_item: SeedItem,
    ///是否消耗物品
    pub is_consume: bool,
}

///收获作物事件
#[derive(Event)]
pub struct EHarvestCrop {
    pub pos: IVec2,
}

///浇水作物事件
#[derive(Event)]
pub struct EWaterCrop {
    pub pos: IVec2,
}

///锄地事件
#[derive(Event)]
pub struct EHoeField {
    pub pos: IVec2,
}

//放置家具事件
#[derive(Event)]
pub struct EPutFurniture {
    pub pos: IVec2,
    pub furniture_component: FurnitureComponent,
    ///是否消耗物品
    pub is_consume: bool,
}

///修改物品事件
#[derive(Event, Debug)]
pub struct EModifyGoods {
    ///物品列表 (物品ID, 数量, 是否是消耗)
    pub goods_list: Vec<(u32, u32, bool)>,
}

impl EModifyGoods {
    pub fn new() -> Self {
        Self {
            goods_list: Vec::new(),
        }
    }

    pub fn add_goods(&mut self, mid: u32, count: u32) -> &mut Self {
        if let Some((_, c, _)) = self.goods_list.iter_mut().find(|(i, _, _)| *i == mid) {
            *c += count;
        } else {
            self.goods_list.push((mid, count, false));
        }
        self
    }
}

///保存游戏事件
#[derive(Event)]
pub struct ESaveGame;

#[derive(Event)]
pub struct EFirstLoadGame;
